//  this library.
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hktk_app/util/view_util.dart';

/// 圆环指示器绘画
class RingPainter extends CustomPainter {
  /// 正确率
  final double accuracy;

  const RingPainter({required this.accuracy});

  @override
  void paint(Canvas canvas, Size size) {
    double pi2 = pi / 90;
    double startPi = pi + pi2;
    double endPi = pi - pi2 - pi2;

    // 以strokeWidth的中心点计算宽度
    // 背景画笔
    Paint bgPaint = Paint()
      ..style = PaintingStyle.stroke
      ..color = colorBlue2
      ..strokeWidth = 16
      ..strokeCap = StrokeCap.round;

    // 背景样式
    // Rect rect = Rect.fromLTWH(8, 8, 374, 374);
    Rect rect = Rect.fromLTWH(8, 30, 1.sw-48,  1.sw-48);

    canvas.drawArc(rect, startPi, endPi, false, bgPaint);

    // 进度画笔
    Paint jdPaint = Paint()
      ..style = PaintingStyle.stroke
      ..color = colorBlue1
      ..strokeWidth = 16
      ..strokeCap = StrokeCap.round;

    // 进度样式
    canvas.drawArc(rect, startPi, endPi * accuracy, false, jdPaint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }
}
